package com.google.code.sms.util;

import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;

/**
 * Miscellaneous general utility methods.
 *
 * @author Sindre Mehus
 */
public final class Util {
    /**
     * Disallow external instantiation.
     */
    private Util() {
    }

    public static String getDefaultMediaFolder() {
        return System.getProperty("sms.defaultMediaFolder", "/var/music");
    }

    public static String getDefaultPlaylistFolder() {
        return System.getProperty("sms.defaultPlaylistFolder", "/var/playlists");
    }

    /**
     * Similar to {@link ServletResponse#setContentLength(int)}, but this method
     * supports lengths bigger than 2GB.
     * <p/>
     * See http://blogger.ziesemer.com/2008/03/suns-version-of-640k-2gb.html
     *
     * @param response The HTTP response.
     * @param length The content length.
     */
    public static void setContentLength(HttpServletResponse response, long length) {
        if (length <= Integer.MAX_VALUE) {
            response.setContentLength((int) length);
        } else {
            response.setHeader("Content-Length", String.valueOf(length));
        }
    }
}